package com.googlecode.vmock.utils;

/**
 * Enumerates all two-argument logic operators for {@link Comparable} objects.
 * 
 * @author marcin.jagus
 */
public enum LogicOperator {

    /**
     * Less than.
     */
    LESS_THAN("<") {
        @Override
        public <T extends Comparable<T>> boolean operate(T a, T b) {
            return a.compareTo(b) < 0;
        }
    },

    /**
     * Less or equal than.
     */
    LESS_EQUAL("<=") {
        @Override
        public <T extends Comparable<T>> boolean operate(T a, T b) {
            return a.compareTo(b) <= 0;
        }
    },

    /**
     * Greater than.
     */
    GREATER_THAN(">") {
        @Override
        public <T extends Comparable<T>> boolean operate(T a, T b) {
            return a.compareTo(b) > 0;
        }
    },

    /**
     * Greater or equal than.
     */
    GREATER_EQUAL(">=") {
        @Override
        public <T extends Comparable<T>> boolean operate(T a, T b) {
            return a.compareTo(b) >= 0;
        }
    },

    /**
     * Equal to.
     */
    EQUAL("==") {
        @Override
        public <T extends Comparable<T>> boolean operate(T a, T b) {
            return a.compareTo(b) == 0;
        }
    },

    /**
     * Not equal to.
     */
    NOT_EQUAL("!=") {
        @Override
        public <T extends Comparable<T>> boolean operate(T a, T b) {
            return a.compareTo(b) != 0;
        }
    };

    /**
     * Mathematical symbol of this operator.
     */
    private String symbol;

    LogicOperator(String symbol) {
        this.symbol = symbol;
    }

    /**
     * Executes this operator on two {@link Comparable} objects.
     * 
     * @param a First object
     * @param b Second object
     * @return Result of this operator
     */
    public abstract <T extends Comparable<T>> boolean operate(T a, T b);

    @Override
    public String toString() {
        return symbol;
    }
}
